package com.century.sjt.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;

import com.android.volley.RequestQueue;
import com.bumptech.glide.Glide;
import com.century.sjt.R;
import com.century.sjt.entity.goodSort;
import com.makeramen.roundedimageview.RoundedImageView;

import java.util.List;

/**
 * Created by pig33 on 15-06-19.
 */
public class GoodSortListViewAdapter extends BaseAdapter {

    private List<goodSort> dataList;
    private LayoutInflater mInflater;
    private RequestQueue mQueue;
    private Context mContext;
    private ItemClickListener listener;
    public GoodSortListViewAdapter(Context context, RequestQueue mQueue, List<goodSort> dataList){
        mInflater= LayoutInflater.from(context);
        this.mQueue=mQueue;
        this.dataList=dataList;
        this.mContext = context;
    }

    @Override
    public int getCount() {
        return dataList.size();
    }

    @Override
    public Object getItem(int position) {
        return  dataList.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(final int position, View convertView, ViewGroup parent) {
        ViewHolder holder;
        if(convertView==null){
            convertView=mInflater.inflate(R.layout.goodsort_item_tab,null);
            holder=new ViewHolder();
            holder.mImageView= (RoundedImageView) convertView.findViewById(R.id.iv_sort_goods_img);
            convertView.setTag(holder);
        }else{
            holder= (ViewHolder) convertView.getTag();
        }

        Glide.with(mContext).load(dataList.get(position).getImage()).into(holder.mImageView);

//        holder.mImageView.setOnClickListener(new View.OnClickListener() {
//            @Override
//            public void onClick(View v) {
//                listener.onClick(position);
//            }
//        });
        return convertView;
    }

    private static class ViewHolder {
//        private TextView Title;
//        private LinearLayout ll_Title;
          private RoundedImageView mImageView;
    }

    public void setItemClickListener(ItemClickListener listener) {
        this.listener = listener;
    }
    public interface ItemClickListener{
        void onClick(int id);
    }
}
